{% if include.selector %}
  {% assign selector = include.selector %}
{% endif %}

{% if include.seed %}
  {% assign seed = include.seed %}
{% endif %}

<script src="/assets/js/geopattern.min.js"></script>
<script>
  function setRandomBgImage(selector, seed) {
    let finalSeed = '';

    if (seed) {
      finalSeed = seed;
    } else {
      const STRING_POOL = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      let times = 12;
      while (times--) {
        const index = Math.floor(Math.random() * 62);
        finalSeed += STRING_POOL[index];
      }
    }

    var pattern = GeoPattern.generate(finalSeed);
    var element = document.querySelector(selector);
    if (element) {
      element.style.backgroundImage = pattern.toDataUrl();
    }
  }

  setRandomBgImage('{{ selector }}', '{{ seed }}');
</script>

